﻿using BigEgg.Framework.Foundation;
using BigEgg.Framework.UnitTesting;
using FMStudio.Domain.Properties;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace FMStudio.Domain.SQLite.Test
{
    [TestClass]
    public class BillTest
    {
        [TestMethod]
        public void GeneralBillTest()
        {
            Bill bill = new Bill();

            Assert.IsNotNull(bill.ID);
            Assert.AreEqual(DateTime.Today, bill.Date);
            Assert.AreEqual(true, bill.Out);
            Assert.AreEqual(0, bill.Index);
            Assert.AreEqual(1.0, bill.Number);
            Assert.AreEqual(100.0, bill.Discount);
            Assert.IsNull(bill.ItemPrice);
            Assert.IsNull(bill.UseType);

            bill.PayTypeString = "000001";
            UseType useType = new UseType();
            bill.UseType = useType;
            ItemPrice itemPrice = new ItemPrice();
            bill.ItemPrice = itemPrice;

            Assert.AreEqual("", bill.Validate());
        }

        [TestMethod]
        public void BillUseTypePropertyChangedTest()
        {
            Bill bill = new Bill();
            Assert.IsNull(bill.UseType);

            UseType useType = new UseType();
            AssertHelper.PropertyChangedEvent(bill, x => x.UseType, () => bill.UseType = useType);
            Assert.AreEqual(useType, bill.UseType);
        }

        [TestMethod]
        public void BillItemPricePropertyChangedTest()
        {
            Bill bill = new Bill();
            Assert.IsNull(bill.ItemPrice);

            ItemPrice itemPrice = new ItemPrice();
            AssertHelper.PropertyChangedEvent(bill, x => x.ItemPrice, () => bill.ItemPrice = itemPrice);
            Assert.AreEqual(itemPrice, bill.ItemPrice);
        }
        
        [TestMethod]
        public void BillPayTypeValidationTest()
        {
            Bill bill = new Bill();

            Assert.AreEqual(string.Empty, bill.PayTypeString);
            Assert.AreEqual(Resources.PayTypeMandatory, bill.Validate("PayTypeString"));

            bill.PayTypeString = "000001";
            Assert.AreEqual("", bill.Validate("PayTypeString"));
            bill.PayTypeString = "100001";
            Assert.AreEqual("", bill.Validate("PayTypeString"));
        }

        [TestMethod]
        public void BillUseTypeValidationTest()
        {
            Bill bill = new Bill();

            Assert.IsNull(bill.UseType);
            Assert.AreEqual(Resources.UseTypeMandatory, bill.Validate("UseType"));

            UseType useType = new UseType();
            bill.UseType = useType;
            Assert.AreEqual("", bill.Validate("UseType"));
        }

        [TestMethod]
        public void BillItemPriceValidationTest()
        {
            Bill bill = new Bill();

            Assert.IsNull(bill.ItemPrice);
            Assert.AreEqual(Resources.ItemPriceMandatory, bill.Validate("ItemPrice"));

            ItemPrice itemPrice = new ItemPrice();
            bill.ItemPrice = itemPrice;
            Assert.AreEqual("", bill.Validate("ItemPrice"));
        }

        [TestMethod]
        public void BillNumberValidationTest()
        {
            Bill bill = new Bill();

            Assert.AreEqual(1, bill.Number);

            bill.Number = 0.1;
            Assert.AreEqual("", bill.Validate("Number"));
            bill.Number = 0.0;
            Assert.AreEqual(Resources.BillNumberGreater, bill.Validate("Number"));
            bill.Number = -0.1;
            Assert.AreEqual(Resources.BillNumberGreater, bill.Validate("Number"));
        }

        [TestMethod]
        public void BillDiscountValidationTest()
        {
            Bill bill = new Bill();

            Assert.AreEqual(100, bill.Discount);

            bill.Discount = 0.1;
            Assert.AreEqual("", bill.Validate("Discount"));
            bill.Discount = 0.0;
            Assert.AreEqual("", bill.Validate("Discount"));
            bill.Discount = -0.1;
            Assert.AreEqual(Resources.BillDiscountGreaterOrEqual, bill.Validate("Discount"));
        }
    }
}
